#ifndef CAMERACONFIG_H
#define CAMERACONFIG_H

#include "configarray.h"
#include "configfile.h"
#include "configobject.h"
#include "configobjectarray.h"

class CameraParameter : public ConfigObject
{
public:
    const QString CAMERA_TYPE_BASLER = "Basler";
    const QString CAMERA_TYPE_HIKVISION = "HIKVision";
    const QString CAMERA_MODE_SW_TRIGGER = "SW Trigger";
    const QString CAMERA_MODE_IO_TRIGGER = "HW Trigger";

    Q_OBJECT
    Q_PROPERTY(QString cameraName READ cameraName WRITE setCameraName NOTIFY cameraNameChanged)
    Q_PROPERTY(QString cameraIP READ cameraIP WRITE setCameraIP NOTIFY cameraIPChanged)
    Q_PROPERTY(QString cameraType READ cameraType WRITE setcameraType NOTIFY cameraTypeChanged)
    Q_PROPERTY(QString cameraMode READ cameraMode WRITE setcameraMode NOTIFY cameraModeChanged)
    Q_PROPERTY(int exposure READ exposure WRITE setExposure NOTIFY exposureChanged)

    QString m_cameraName = "dummy";
    QString m_cameraType = CAMERA_TYPE_BASLER;
    QString m_cameraMode = CAMERA_MODE_SW_TRIGGER;
    QString m_cameraIP;
    int m_exposure = 5000;

public:
    CameraParameter(QObject *parent = nullptr) : ConfigObject(parent)
    {
        {
            QVariantList stringOptions;
            stringOptions.append(CAMERA_TYPE_BASLER);
            stringOptions.append(CAMERA_TYPE_HIKVISION);
            setOptionalProperty("cameraType", stringOptions);
        }
        {
            QVariantList stringOptions;
            stringOptions.append(CAMERA_MODE_SW_TRIGGER);
            stringOptions.append(CAMERA_MODE_IO_TRIGGER);
            setOptionalProperty("cameraMode", stringOptions);
        }
        init();
    }

    QString cameraName() const
    {
        return m_cameraName;
    }

    QString cameraType() const
    {
        return m_cameraType;
    }

    QString cameraMode() const
    {
        return m_cameraMode;
    }

    QString cameraIP() const
    {
        return m_cameraIP;
    }

    int exposure() const
    {
        return m_exposure;
    }

public slots:
    void setCameraName(QString cameraName)
    {
        if (m_cameraName == cameraName)
            return;

        m_cameraName = cameraName;
        emit cameraNameChanged(m_cameraName);
    }
    void setcameraType(QString cameraType)
    {
        if (m_cameraType == cameraType)
            return;

        m_cameraType = cameraType;
        emit cameraTypeChanged(m_cameraType);
    }

    void setcameraMode(QString cameraMode)
    {
        if (m_cameraMode == cameraMode)
            return;

        m_cameraMode = cameraMode;
        emit cameraModeChanged(m_cameraMode);
    }

    void setCameraIP(QString cameraIP)
    {
        if (m_cameraIP == cameraIP)
            return;

        m_cameraIP = cameraIP;
        emit cameraIPChanged(m_cameraIP);
    }

    void setExposure(int exposure)
    {
        if (m_exposure == exposure)
            return;

        m_exposure = exposure;
        emit exposureChanged(m_exposure);
    }

signals:
    void cameraNameChanged(QString cameraName);
    void cameraTypeChanged(QString cameraType);
    void cameraModeChanged(QString cameraMode);
    void cameraIPChanged(QString cameraIP);
    void exposureChanged(int exposure);
};

class CameraConfig : public ConfigObject
{
    Q_OBJECT
    Q_PROPERTY(ConfigObjectArray *cameraParameterArray READ cameraParameterArray)

    ConfigObjectArray * m_cameraParameterArray;

public:
    CameraConfig(QObject *parent = nullptr) : ConfigObject(parent)
    {        
        m_cameraParameterArray = new ConfigObjectArray("CameraParameter");
        m_cameraParameterArray->setObjectName("m_cameraParameterArray");
        init();
    }

    ConfigObjectArray * cameraParameterArray() const
    {
        return m_cameraParameterArray;
    }
};

#endif // CAMERACONFIG_H
